package com.lagou.bean;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ExcutorService {

    public void doExe(MonitorComponet  service) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 10, 200, TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<Runnable>(5));

        for(int i=0;i<15;i++){
            MyTask myTask = new MyTask(i,service);
            executor.execute(myTask);
            /*System.out.println("线程池中线程数目："+executor.getPoolSize()+"，队列中等待执行的任务数目："+
                    executor.getQueue().size()+"，已执行玩别的任务数目："+executor.getCompletedTaskCount());*/
        }
        executor.shutdown();
    }
}

    class MyTask implements Runnable {
        private int taskNum;
        private MonitorComponet service;

        public MyTask(int num,MonitorComponet service) {
            this.taskNum = num;
            this.service = service;
        }

        @Override
        public void run() {
            //System.out.println("正在执行task "+taskNum);

            try {
                service.methodA();
                service.methodB();
                service.methodC();
                //Thread.currentThread().sleep(4000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //System.out.println("task "+taskNum+"执行完毕");
        }

}
